﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace sieuthi
{
    public partial class cungcap : Form
    {
        private SqlDataAdapter da = new SqlDataAdapter();
        private SqlConnection conn = new SqlConnection(Threelayer.VO.core.connectionsring.ToString());
        private SqlCommand cmd = new SqlCommand();
        private DataTable dt = new DataTable("cungcap");
        Threelayer.VO.cungcapVO cc_vo;
        Threelayer.BUS.cungcapBUS cc_bus;
        public cungcap()
        {
            InitializeComponent();
        }

        private void cungcap_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'sieuthiDataSet2.cungcap' table. You can move, or remove it, as needed.
            this.cungcapTableAdapter.Fill(this.sieuthiDataSet2.cungcap);
            // TODO: This line of code loads data into the 'sieuthiDataSet2.mathang' table. You can move, or remove it, as needed.
            this.mathangTableAdapter.Fill(this.sieuthiDataSet2.mathang);
            // TODO: This line of code loads data into the 'sieuthiDataSet2.nhacungcap' table. You can move, or remove it, as needed.
            this.nhacungcapTableAdapter.Fill(this.sieuthiDataSet2.nhacungcap);
            cungcapdatabinding();

        }
        private void cungcapdatabinding()
        {
            box_mancc.DataBindings.Clear();
            box_mancc.DataBindings.Add("text", dataGridchitiet.DataSource, "mancc");
            box_gia.DataBindings.Clear();
            box_gia.DataBindings.Add("text", dataGridchitiet.DataSource, "gia");
            box_mamh.DataBindings.Clear();
            box_mamh.DataBindings.Add("text", dataGridchitiet.DataSource, "mamh");
        }
        private void data_cungcap()
        {
            cc_vo = new Threelayer.VO.cungcapVO();
            cc_vo.Gia = box_gia.Text;
            cc_vo.MaMh = box_mamh.Text;
            cc_vo.MaNcc = box_mancc.Text;
        }

        private void bt_cungcap_them_Click(object sender, EventArgs e)
        {
            data_cungcap();
            cc_bus = new Threelayer.BUS.cungcapBUS();
            cc_bus.cungcap_them(cc_vo);
            cungcap_Load(sender, e);
            cungcapdatabinding();
        }

        private void bt_cungcap_sua_Click(object sender, EventArgs e)
        {
            data_cungcap();
            cc_bus = new Threelayer.BUS.cungcapBUS();
            cc_bus.cungcap_sua(cc_vo);
            cungcap_Load(sender, e);
            cungcapdatabinding();
        }

        private void bt_cungcap_xoa_Click(object sender, EventArgs e)
        {
            data_cungcap();
            cc_bus = new Threelayer.BUS.cungcapBUS();
            cc_bus.cungcap_xoa(box_cungcap_timkiem.Text);
            cungcap_Load(sender, e);
            cungcapdatabinding();
        }

        private void bt_cungcap_timkiem_Click(object sender, EventArgs e)
        {
            dt.Clear();
            cmd.Dispose();
            cmd.Parameters.Clear();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.StoredProcedure;
            conn.Open();
            cmd.CommandText = "cungcap_timkiem";
            cmd.Parameters.Add("@mancc", SqlDbType.NVarChar, 200).Value = box_cungcap_timkiem.Text;
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            cmd.ExecuteNonQuery();
            da.Fill(dt);
            dataGridchitiet.DataSource = dt;
            conn.Close();

        }
    }
}
